﻿//************************************************************************
//* Written by Jirat Boomuang
//* Filename: Program.cs
//* Revision: 1.0
//* Author: JiratB
//* Platform: .NET Framework 4.0
//* Description: Code for generating CRM contacts for performance testing
//* 
//************************************************************************

//************************************************************************
//* Revision History
//------------------------------------------------------------------------
//* Revision  Date      Signature    Description
//------------------------------------------------------------------------
//* 1.0       20130119  JiratB       - First release to Codeplex
//************************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//-- CRM References --
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk;
//--------------------

//-- Solution References --
using AdaCRMUtilities;
//--------------------

namespace contact_generator
{
    class Program
    {
        static void Main(string[] args)
        {
            OrganizationUtils orgUtils = new OrganizationUtils(args);

            IOrganizationService crmService = orgUtils.GetOrganization();

            string contactFirstname;
            string contactLastname;

            int i = Convert.ToInt32(args[3]);
            while (--i > 0)
            {
                Entity contact = new Entity("contact");

                contactFirstname = AdaRandomUtils.RandomUpperCase(10);
                contactLastname = AdaRandomUtils.RandomUpperCase(8) + AdaRandomUtils.RandomNumber(8);

                contact.Attributes["firstname"] = contactFirstname;
                contact.Attributes["lastname"] = contactLastname;
                contact.Attributes["emailaddress1"] = "random@doesnotexist.com";
                contact.Attributes["telephone1"] = AdaRandomUtils.RandomPhoneNumber("+66", "2", 7);
                contact.Attributes["telephone2"] = AdaRandomUtils.RandomPhoneNumber("+66", "2", 7);
                contact.Attributes["fax"] = AdaRandomUtils.RandomPhoneNumber("+66", "2", 7);
                contact.Attributes["websiteurl"] = "htt://www.doesnotexist.com";
                contact.Attributes["annualincome"] = (double)AdaRandomUtils.RandomInt(72000, 100000000);
                //contact.Attributes["vxrm_iscustomer"] = true; //-- to be used with Jirat's Account and Contact solution only

                crmService.Create(contact);

                #region Display The Created Account
                Console.WriteLine("[{0}]: Contact \"{1} {2}\" is created. ",
                    i, contactFirstname, contactLastname);
                #endregion
            }//-- end of while loop --

            Console.WriteLine(orgUtils.GetOrganization().ToString());
            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
        }//-- End of Main --
    }//-- End of Class --
}//-- End of Namespace --

//************************************************************************
// End of file
//************************************************************************

